function getQuestion() {
  const username = document.getElementById("username").value;
  axios
    .get(`http://localhost:4407/api/User/GetQuestion?username=${username}`)
    .then((response) => {
      if (response.data.question) {
        document.getElementById("question").value = response.data.question;
      } else {
        alert("获取安全问题失败: " + response.data.msg);
      }
    })
    .catch((error) => console.error("Error:", error));
}

document
  .getElementById("forgotPasswordForm")
  .addEventListener("submit", function (e) {
    e.preventDefault();
    const data = {
      username: document.getElementById("username").value,
      answer: document.getElementById("answer").value,
      password: document.getElementById("newPassword").value,
    };

    axios
      .post("http://localhost:4407/api/User/UpdatePassword", data, {
        headers: {
          "Content-Type": "application/json",
        },
      })
      .then((response) => {
        const data = response.data;
        if (data.msg === "修改成功") {
          // localStorage.setItem('token', data.token);
          window.location.href = "Login.html";
        } else {
          alert("登录失败: " + data.msg);
        }
      })
      .catch((error) => console.error("Error:", error));
  });
